//
//  Kingfisher+Rx.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/8.
//

import Foundation

import UIKit
import RxSwift
import RxCocoa
import Kingfisher
///使用方法
//viewModel.avatarURL
//    .compactMap { URL(string: $0) }
//    .bind(to: imageView.rx.imageURL)
//    .disposed(by: disposeBag)
extension Reactive where Base : UIImageView{
    var imageURL : Binder<URL> {
        return Binder(self.base) { imageView, url in
            DispatchQueue.main.async {
                imageView.kf.setImage(with: url)
            }
        }
    }
}
///使用方法
///viewModel.avatarURL
//    .map { URL(string: $0) }
//    .bind(to: imageView.rx.imageURL(placeholder: UIImage(named: "default_avatar")))
//    .disposed(by: disposeBag)
extension Reactive where Base : UIImageView {
    func imageURL(placeholder : UIImage? = nil,options : KingfisherOptionsInfo? = nil) -> Binder<URL> {
        return Binder(self.base) { imageView , url in
            DispatchQueue.main.async {
                imageView.kf.setImage(with: url ,placeholder: placeholder ,options:  options)
            }
            
        }
    }
}

